package com.example.java8.timeapi;

import java.time.*;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;
import java.time.temporal.TemporalUnit;
import java.util.List;

/**
 * TODO
 *
 * @author qibao
 * @version v0.1 2020/12/17
 */
public class TimeDemo {
    public static void main(String[] args) {
//        localDateTimeTest();
//        instantTest();
        beteenTime();
    }

    /**
     * locaDateTime
     */
    public static void localDateTimeTest() {
        LocalDateTime.now();
        LocalDateTime localDateTime = LocalDateTime.of(2020, 10, 10, 10, 10);
        localDateTime.minusMonths(1);
        localDateTime.plusDays(10);

    }

    /**
     * instant
     */
    public static void instantTest() {
        Instant instant = Instant.now();
        System.out.println(instant.toString());
        OffsetDateTime offsetDateTime = instant.atOffset(ZoneOffset.ofHours(8));
        System.out.println(offsetDateTime.getHour());
    }

    /**
     * 时间间隔
     */
    public static void beteenTime() {
        LocalDate localDate = LocalDate.now();
        Period period = Period.between(localDate, localDate.plusDays(10));
        Long millis = period.get(ChronoUnit.DAYS);
        Integer days = period.getDays();

        System.out.println(millis);
        System.out.println(days);
    }
}
